package ${sourceBasePackage}.controller;

import ${sourceBasePackage}.api.${entityPackage?uncap_first}.${className}ServiceClient;
import ${sourceBasePackage}.common.api.JsonResult;
import ${sourceBasePackage}.common.api.Page;
import ${sourceBasePackage}.common.api.PageData;
import ${sourceBasePackage}.common.base.BaseController;
import ${sourceBasePackage}.common.entity.${className};
import ${sourceBasePackage}.service.${className}Service;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 *
 * @author:
 * <pre>
 * SD
 * 	${author}
 * PG
 *	${author}
 * </pre>
 * @description: ${description}controller
 * @data: ${createDate}
 * @copyright: zooocloud.com
 *
 */
@Api(value = "${description}", description = "${description}")
@RestController
public class ${className}Controller extends BaseController implements ${className}ServiceClient {

	@Autowired
	private  ${className}Service ${className?uncap_first}Service;

	/**
	 * @description:
	 * <pre>
	 * 	${createDate} ${author}
	 * 	分页查询、搜索
	 * </pre>
	 * 
	 * @param page
	 * @param rows
	 * @return JsonResult
	 */
	@Override
	@ApiOperation(value = "分页查询、搜索")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "page", value = "当前页码", dataType = "int", paramType = "query"),
		@ApiImplicitParam(name = "rows", value = "每页条数", dataType = "int", paramType = "query")
	})
	public JsonResult<${className}> list(Integer page, Integer rows) throws Exception {
		JsonResult<${className}> jr = new JsonResult<>();
		PageData pd = new PageData(request);
		if(page!=null && page>0){
			// 分页
			Page pg = new Page(pd);
			jr.setDatas(${className?uncap_first}Service.findByPage(pg));
			jr.setOutputPage(new JsonResult.OutputPage(pg));
		}else{
			// 搜索
			jr.setDatas(${className?uncap_first}Service.findBySearch(pd));
		}
        return jr;
	}
	
	/**
	 * @description:
	 * <pre>
	 * 	${createDate} ${author}
	 * 	根据id查询
	 * </pre>
	 * 
	 * @param id
	 * @return JsonResult
	 */
	@Override
	@ApiOperation(value = "${description}信息")
	public JsonResult<${className}> info(@PathVariable ${pkType} ${pkField}) throws Exception {
		return new JsonResult<>(${className?uncap_first}Service.getById(${pkField}));
	}

	/**
	 * @description:
	 * <pre>
	 * 	${createDate} ${author}
	 * 	添加
	 * </pre>
	 *
	 * @param ${className?uncap_first}
	 * @return JsonResult
	 */
	@Override
	@ApiOperation(value = "添加${description}")
	public JsonResult<${className}> add(@RequestBody ${className} ${className?uncap_first}) throws Exception {
		return new JsonResult<>(${className?uncap_first}Service.add(${className?uncap_first}));
	}
	
	/**
	 * @description:
	 * <pre>
	 * 	${createDate} ${author}
	 * 	修改
	 * </pre>
	 *
	 * @param ${pkField}
	 * @param ${className?uncap_first}
	 * @return JsonResult
	 */
	@Override
	@ApiOperation(value = "修改${description}")
	public JsonResult<${className}> update(@PathVariable ${pkType} ${pkField}, @RequestBody ${className} ${className?uncap_first}) throws Exception {
		${className?uncap_first}.set${pkField?cap_first}(${pkField});
		return new JsonResult<>(${className?uncap_first}Service.update(${className?uncap_first}));
	}
	
	/**
	 * @description:
	 * <pre>
	 * 	${createDate} ${author}
	 * 	删除
	 * </pre>
	 * 
	 * @param ${pkField}
	 * @return JsonResult
	 */
	@Override
	@ApiOperation(value = "删除${description}")
	public JsonResult<Boolean> delete(@PathVariable ${pkType} ${pkField}) throws Exception {
		${className?uncap_first}Service.delete(${pkField});
		return new JsonResult<>(true);
	}
}
